var uploadFile;
var sliceId;
var dicomPath;
var jpgPath;
var httpPath;
var physicalTime;

//气泡提示栏
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
});
//
showLoading = function (loadText) {
    if(!loadText){
        $("#loadText").html(loadText)
    }
    $('#loadingModal').modal({backdrop: 'static', keyboard: false});
}
hideLoading = function () {
    $('#loadingModal').modal('hide');
}

//dicom文件上传
function saveFile(file) {
    uploadFile = file;
    $("#fileName").html(file.name);

    var formData = new FormData();
    formData.append("file", file);
    $.ajax({
        type: "POST",
        url: "/file/uploadDicom",
        dataType: "json",
        processData: false,
        contentType: false,
        enctype: "multipart/form-data",
        xhrFields: {withCredentials:true},	//前端适配：允许session跨域
        crossDomain: true,
        data: formData,
        success: function (data) {
            //var result = JSON.parse(data);
            if (data.code == 1) {
                alert("上传成功")
                sliceId = data.sliceId;

                if (data.date != 0)  {
                    //alert(data.date)
                    document.getElementById("checkDate").value = '' + data.date;
                }
                document.getElementById("dicomImg").src = '' + data.url;
                document.getElementById("imgText").innerText = "上传的图像.";
                // dicomPath = data.DicomPath;
                // jpgPath = data.JpgSavePath;
                // httpPath = data.HttpPath;
                // physicalTime = data.StudyDate;
            }else {
                alert("上传失败")
                location.reload();
            }
        },
        error: function () {
            alert("请求错误")
        }
    })
}

//切片信息入库
function distinguish() {
    var mySelect = document.getElementById("idSelect");
    var index = mySelect.selectedIndex;
    //Param
    var selectId = mySelect.options[index].value;
    var height = $("#height").val();
    var weight = $("#weight").val();
    var time = $("#checkDate").val();
    var file = uploadFile;

    if (selectId == "" || height == "" || weight == "" || file == null || time == "") {
        alert("请填写必须栏目");
        return false;
    }

    //显示加载动画
    showLoading();

    // document.getElementById('loadpagediv').style.display =  "inline";
    // var floatBg = document.getElementById("float-bg");
    // floatBg.style.width= document.body.scrollWidth + "px";
    // floatBg.style.height = document.body.scrollHeight + "px";
    // document.getElementById('float-bg').style.display =  "inline";

    $.ajax({
        type: "POST",
        url: "analysis",
        dataType: "json",
        xhrFields: {withCredentials:true},	//前端适配：允许session跨域
        crossDomain: true,
        contentType:"application/x-www-form-urlencoded",
        data: {height:height, weight:weight, youthId: selectId, sliceId: sliceId, time:time},
        success: function (data) {
            if (data.code == 1) {
                // document.getElementById('loadpagediv').style.display =  "none";
                // document.getElementById('float-bg').style.display =  "none";
                hideLoading();
                alert("识别成功")
                window.location.href = "/result?sliceId=" + sliceId;
            }else {
                // document.getElementById('loadpagediv').style.display =  "none";
                // document.getElementById('float-bg').style.display =  "none";
                hideLoading();
                alert("请求错误:" + data.msg);
                location.reload();
            }
        },
        error: function () {
            alert("网络错误");
        }

    })
}